//
//  RequestBase.h
//  HuiMei
//  联网基类
//  处理通用方法，如状态码的解析等
//  Created by 王越 on 15/6/30.
//  Copyright (c) 2015年 王越. All rights reserved.
//

#import <Foundation/Foundation.h>


//状态码
enum OPERATION_CODE{
    //操作成功
    SUCCESS_OPERATION = 100,
    //session失效
    SessionFailure = 121,
    //有新版本更新!
    HAVEVERSIONUPDATE_ERROR=106,
};


//联网代理
@protocol RequestBaseDelegate <NSObject>

/**联网百分比*/
@optional
-(void)progress:(NSProgress*)progress;

/**解析数据*/
@optional
-(void)parserData:(NSDictionary *)dic;

/*联网解析完成*/
- (void)requestSuccess:(NSObject *)message;

/*联网错误*/
@optional
- (void)requestFailed:(NSString *)errorMessage;

/*取消联网*/
@optional
- (void)requestCancel;

@end


/**
 *  联网基类
 */
@interface RequestBase : NSObject

/**网络请求的提示信息*/
@property (nonatomic,strong) NSString *dialogMessage;
/**对话框是否显示*/
@property (nonatomic,assign) BOOL isHiddenDialog;
/**网络请求是否可以取消*/
@property (nonatomic,assign) BOOL isCancel;

/**网络请求信息*/
@property(nonatomic ,strong) NSString *responseMessage;
/**网络请求状态码*/
@property(nonatomic, assign) int responseCode;

/**回调 block 类型声明*/
typedef void(^CAll_BACK)(NSObject *);
/**进度的回调*/
@property (nonatomic, copy) CAll_BACK progressBack;
/**成功的回调*/
@property (nonatomic, copy) CAll_BACK successBack;
/**失败的回调*/
@property (nonatomic, copy) CAll_BACK failBack;


/**
 *  get联网方法
 *
 *  @param url      url description
 *  @param postBody <#postBody description#>
 *  @param delegate <#delegate description#>
 */
- (void)doGetRequest:(NSString *)url
            PostBody:(NSDictionary *)postBody
            Delegate:(id<RequestBaseDelegate>)delegate;

/**
 *  post联网方法
 *
 *  @param url      <#url description#>
 *  @param postBody postBody description
 *  @param delegate <#delegate description#>
 */
- (void)doPostRequest:(NSString *)url
             PostBody:(NSDictionary *)postBody
             Delegate:(id<RequestBaseDelegate>)delegate;

/**
 *  表单提交数据
 *
 *  @param url      <#url description#>
 *  @param postBody <#postBody description#>
 *  @param data     <#data description#>
 *  @param delegate <#delegate description#>
 */
- (void)doPostFormDataRequest:(NSString *)url
                     PostBody:(NSDictionary *)postBody
                     FormData:(NSDictionary *)data
                     Delegate:(id<RequestBaseDelegate>)delegate;

/**
 *  下载文件
 *
 *  @param url      url description
 *  @param downloadFilePath downloadFilePath description
 *  @param delegate <#delegate description#>
 */
- (void)doDownlodFileRequest:(NSString *)url
                        Path:(NSString *)downloadFilePath
                    Delegate:(id<RequestBaseDelegate>)delegate;

@end
